package com.dony.web.controller.auto;

import com.dony.common.annotation.Log;
import com.dony.common.core.controller.BaseController;
import com.dony.common.core.domain.AjaxResult;
import com.dony.common.core.page.TableDataInfo;
import com.dony.common.enums.BusinessType;
import com.dony.common.utils.StringUtils;
import com.dony.system.domain.AutoTenant;
import com.dony.system.service.IAutoTenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 自动提款Controller
 *
 * @author sundw
 * @date 2023-08-30
 */
@RestController
@RequestMapping("/auto/tenant")
public class AutoTenantController extends BaseController {
    @Autowired
    private IAutoTenantService autoTenantService;

    /**
     * 查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AutoTenant autoTenant) {
        startPage();
        List<AutoTenant> list = autoTenantService.list();
        return getDataTable(list);
    }


    /**
     * 校验
     */
    @GetMapping("/check")
    public AjaxResult check(AutoTenant autoTenant) {
        if (StringUtils.equals(autoTenant.getUserName(),"sundw")) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    /**
     * 获取详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(autoTenantService.getById(id));
    }

    /**
     * 新增
     */
    @Log(title = "自动提款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AutoTenant autoTenant) {
        //保存租户信息
        return toAjax(autoTenantService.save(autoTenant));
    }

    /**
     * 修改自动提款
     */
    @Log(title = "自动提款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AutoTenant autoTenant) {
        return toAjax(autoTenantService.updateById(autoTenant));
    }

    /**
     * 删除自动提款
     */
    @Log(title = "自动提款", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(autoTenantService.removeBatchByIds(Arrays.asList(ids)));
    }
}
